package cn.sytton.taffe.code.util;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ArrayUtil;

import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * 代码路径工具类
 *
 * @author skyrock
 */
public class PathUtil {

    public static String getTsApiPath(String srcPath, String moduleName) {
        return createPath(srcPath, new String[]{"api", "modules", moduleName});
    }
    public static String getVuePath(String srcPath, String moduleName, String subPath) {
        return createPath(srcPath, new String[]{"views", moduleName, subPath});
    }

    public static String getJavaPath(String srcPath, String packageName, String... subPath) {
        String[] pathJava = ArrayUtil.addAll(new String[]{"main","java"},packageName.split("\\."));
        return createPath(srcPath, pathJava, subPath);
    }
    public static  String getXmlPath(String srcPath, String packageName) {
        String[] pathXml = {"main","resources", "mapper"};
        return createPath(srcPath, pathXml);
    }
    private static String createPath(String srcPath, String[] basePath, String... subPath) {
        String[] pathArray = ArrayUtil.addAll(basePath, subPath);
        Path path = Paths.get(srcPath, pathArray);
        FileUtil.mkdir(path);
        return path.toString();
    }
}
